#!/bin/bash 
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage3}
SRC=${SRC:-/sources}

name=perl
version=5.32.1

rm -fr $TMP
rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.xz -C $TMP

{ time \
   {

    cd $TMP/$name-$version

	export BUILD_ZLIB=False
	export BUILD_BZIP2=0

	sh Configure -des                                                 \
	             -Dprefix=/usr                                        \
	             -Dvendorprefix=/usr                                  \
	             -Dprivlib=/usr/lib/perl5/${version::4}/core_perl      \
	             -Darchlib=/usr/lib/perl5/${version::4}/core_perl      \
	             -Dsitelib=/usr/lib/perl5/${version::4}/site_perl      \
	             -Dsitearch=/usr/lib/perl5/${version::4}/site_perl     \
	             -Dvendorlib=/usr/lib/perl5/${version::4}/vendor_perl  \
	             -Dvendorarch=/usr/lib/perl5/${version::4}/vendor_perl \
	             -Dman1dir=/usr/share/man/man1                        \
	             -Dman3dir=/usr/share/man/man3                        \
	             -Dpager="/usr/bin/less -isR"                         \
	             -Duseshrplib                                         \
	             -Dusethreads

    make

    make install
    unset BUILD_ZLIB BUILD_BZIP2
    
    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
